/**
 * @summary: 我的反馈、反馈管理的表格复用逻辑
 * @author: lixinxiang@vv.cn
 */

import React, { useMemo, useCallback } from 'react';
import { Typography } from 'antd';
import { eventTrack } from '@/utils/track';
import TableFilter from '@/components/TableFilter';

const filters = [
    {
        text: '待办',
        value: '待办'
    },
    {
        text: '测试进行中',
        value: '测试进行中'
    },
    {
        text: '研发进行中',
        value: '研发进行中'
    },
    {
        text: '产品进行中',
        value: '产品进行中'
    },
    {
        text: '测试已完成',
        value: '测试已完成'
    },
    {
        text: '研发已完成',
        value: '研发已完成'
    },
    {
        text: '产品已完成',
        value: '产品已完成'
    },
    {
        text: '研发完成无需测试',
        value: '研发完成无需测试'
    },
    {
        text: '完成',
        value: '完成'
    }
];
const useColumns = dispatch => {
    const handleOpen = useCallback(
        record => () => {
            console.log(record, 'record')
            dispatch({ type: 'feedback/processVisible', payload: true });
            dispatch({ type: 'feedback/fetchProgress', payload: record });
            // 埋点
            eventTrack({
                eventName: 'personal_feedbacks_list_context_click',
                pageName: 'personal_feedbacks',
                eventProps: {
                    click_context: record.frontTitle
                }
            });
        },
        [dispatch]
    );

    const columns = useMemo(
        () => [
            {
                title: '编号',
                dataIndex: 'jirano',
                key: 'jirano'
            },
            {
                title: '反馈标题',
                dataIndex: 'frontTitle',
                key: 'frontTitle',
                // width: 200,
                render: text => (
                    <Typography.Text style={{ marginBottom: 0, maxWidth: 300 }} title={text} ellipsis>
                        {text}
                    </Typography.Text>
                )
            },
            // {
            //     title: '路径',
            //     dataIndex: 'frontUrl',
            //     key: 'frontUrl',
            //     width: 250,
            //     render: text => (
            //         <Typography.Text
            //             style={{ width: 250, marginBottom: 0 }}
            //             title={text}
            //             ellipsis
            //             copyable={text !== ''}
            //         >
            //             {text}
            //         </Typography.Text>
            //     )
            // },
            // {
            //     title: '描述',
            //     dataIndex: 'bugDesc',
            //     key: 'bugDesc',
            //     width: 250,
            //     render: text => (
            //         <Typography.Text style={{ width: 250, marginBottom: 0 }} title={text} ellipsis>
            //             {text}
            //         </Typography.Text>
            //     )
            // },
            {
                title: '反馈人',
                dataIndex: 'createUser',
                key: 'createUser'
            },
            {
                title: '反馈时间',
                dataIndex: 'createTime',
                key: 'createTime',
                sorter: () => {}
            },
            {
                title: '状态',
                dataIndex: 'bugStatus',
                key: 'bugStatus',
                filterDropdown: filterProps => <TableFilter {...filterProps} />,
                filterMultiple: false,
                filters
            },
            {
                title: '操作',
                key: 'action',
                width: 100,
                fixed: 'right',
                render: (_, record) => (
                    <a onClick={handleOpen(record)}>{Number(record.bugType) === 3 ? '已结束' : '查看进度'}</a>
                )
            }
        ],
        []
    );

    return columns;
};

export default useColumns;
